package com.threader.bo;

import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.Timer;

public class Time extends Timer {
	private static final long serialVersionUID = -8459730516998441793L;

	public static final int SEC = 1000;
	public static final int MINUTE = SEC*60;
	public static final int HOUR = MINUTE*60;
	public static final int HOUR_QUARTER = MINUTE*15;

	private Date startDate = null;
	// new Date(new Date(2009,9,18,0,0).getTime());

	/**
	 * From Epoch.
	 **/
	private long currentDate = 1000 * 60 * 60 * 4;

	public long interval = MINUTE*5;
	
	public Time(int delay, ActionListener listener) {
		super(delay, listener);
		this.startDate = new Date(0);
	}

	// public static void main(String[] args){
	// System.out.println(new Date(1000));
	// System.out.println(new Date(2000));
	// // System.out.println(new
	// SimpleDateFormat("  dd MMMMM yyyy GGG   HH:mm:ss  ").format(new
	// Date(0)));
	// // System.out.println(new
	// SimpleDateFormat("dd MMMMM yyyy GGG   HH:mm:ss").format(new
	// Date(-1000*60*60-1000).getTime()));
	// }

	public long getCurrentDate() {
		return getStartDate().getTime() + currentDate;
	}

	public String getCurrentTime() {
		return getHour() + ":" + getMinute();
	}

	public void setCurrentDate(long currentDate) {
		this.currentDate = currentDate;
	}
	public void setCurrentDate() {
		this.currentDate = this.getCurrentDate()+this.interval;
	}

	public String toString() {
		return new SimpleDateFormat(" EEEE, HH:mm:ss, dd MMMMM yyyy, GGG  ")
				.format(new Date(getCurrentDate()));
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getStartDate() {
		return startDate;
	}

	public String getMonth() {
		return new SimpleDateFormat("MMM").format(new Date(getCurrentDate()));
	}

	public String getYear() {
		return new SimpleDateFormat("yyyy").format(new Date(getCurrentDate()));
	}

	public String getDay() {
		return new SimpleDateFormat("dd").format(new Date(getCurrentDate()));
	}

	public String getWeek() {
		return new SimpleDateFormat("EEE").format(new Date(getCurrentDate()));
	}

	public String getHour() {
		return new SimpleDateFormat("HH").format(new Date(getCurrentDate()));
	}

	public String getMinute() {
		return new SimpleDateFormat("mm").format(new Date(getCurrentDate()));
	}

	public String getSeconds() {
		return new SimpleDateFormat("ss").format(new Date(getCurrentDate()));
	}

}
